module.exports = function ($scope, $resource, $modalInstance, $modal, toaster, travel, getDate, people) {

    $scope.group = travel;
    $scope.updateFlag = false;
    if(people){
        $scope.people = angular.copy(people);
        $scope.travel_time = travel.travel_time;
        $scope.updateFlag = true;
    } else {
        $scope.people = {'sex': '1'};
    }

    $scope.ok = function(){
        if(!$scope.people.name){
            toaster.warning({title: '', body: '请填写游客姓名'});
            return;
        }
        if(!$scope.people.mobile){
            toaster.warning({title: '', body: '请填写游客联系手机'});
            return;
        }
        if(!$scope.people.cardno){
            toaster.warning({title: '', body: '请填写游客身份证号'});
            return;
        }
        if(!$scope.travel_time){
            toaster.warning({title: '', body: '请选择出游日期'});
            return;
        }
        if($scope.updateFlag){
            $scope.people.sale_code = people.sale_code;
        } else {
            $scope.people.sale_code = $scope.saleInfo.sale_code;
        }
        $scope.people.group_code = travel.group_code;
        $resource('/api/ac/goc/travelInfoService/addTravelInfo', {}, {}).save($scope.people, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '成功'});
                $modalInstance.close($scope.people);
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

    $scope.selectDate = function () {
        if($scope.updateFlag) return;
        var modalInstance = $modal.open({
            template: require('../views/priceCalendar.html'),
            controller: 'priceCalendar',
            size: 'lg',
            resolve: {
                getDate : function(utilservice){
					return utilservice.getDate;
				},
                travel: function () {
                    return travel;
                }
            }
        });
        modalInstance.result.then(function (result) {
            $scope.travel_time = result.date;
            $scope.saleInfo = result;
        });
    }


};